package com.mt.customer.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.customer.entity.DeviceTokenEntity;
import com.mt.customer.mapper.DeviceTokenEntityMapper;

@Component
public class DeviceTokenServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DeviceTokenServiceModel.class);

    @Autowired
    private DeviceTokenEntityMapper deviceTokenEntityMapper;

    public ServiceResult<List<DeviceTokenEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.deviceTokenEntityMapper, "Property 'deviceTokenEntityMapper' is required.");
        ServiceResult<List<DeviceTokenEntity>> result = new ServiceResult<List<DeviceTokenEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.deviceTokenEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[DeviceTokenServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<DeviceTokenEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.deviceTokenEntityMapper, "Property 'deviceTokenEntityMapper' is required.");
        ServiceResult<DeviceTokenEntity> result = new ServiceResult<DeviceTokenEntity>();
        try {
            result.setResult(this.deviceTokenEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[DeviceTokenServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(DeviceTokenEntity deviceTokenEntity) {
        Assert.notNull(this.deviceTokenEntityMapper, "Property 'deviceTokenEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.deviceTokenEntityMapper.insert(deviceTokenEntity);
            if (save > 0) {
                id = deviceTokenEntity.getDeviceTokenId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[DeviceTokenServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(DeviceTokenEntity deviceTokenEntity) {
        Assert.notNull(this.deviceTokenEntityMapper, "Property 'deviceTokenEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.deviceTokenEntityMapper.updateByPrimaryKeySelective(deviceTokenEntity);
            if (save > 0) {
                id = deviceTokenEntity.getDeviceTokenId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[DeviceTokenServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(DeviceTokenEntity deviceTokenEntity) {
        Assert.notNull(this.deviceTokenEntityMapper, "Property 'deviceTokenEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.deviceTokenEntityMapper.updateByPrimaryKeySelective(deviceTokenEntity);
            if (save > 0) {
                id = deviceTokenEntity.getDeviceTokenId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[DeviceTokenServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer deviceTokenId) {
        Assert.notNull(this.deviceTokenEntityMapper, "Property 'deviceTokenEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.deviceTokenEntityMapper.deleteByPrimaryKey(deviceTokenId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[DeviceTokenServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
